package net.cooltain.warhammer.running.window.panel;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.swing.JLabel;

import net.cooltain.warhammer.running.entity.DiscardZone;
import net.cooltain.warhammer.running.entity.MotionPlayerZone;
import net.cooltain.warhammer.running.window.MainFrame;

/**
 * 默认规则：双方都可以看到对方的弃牌堆的每一张卡片
 * @author cooltian
 *
 */
public class DisCardLabel extends JLabel implements MouseListener {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -2045966061927030692L;
	
	private MotionPlayerZone player ; 	// 显示这个卡片的玩家,不一定是拥有卡片的人
	private DiscardZone   discardZone ; // 卡牌堆
	
	public DisCardLabel(MotionPlayerZone player,DiscardZone discardZone) {
		super();
		this.discardZone = discardZone;
		this.player = player;
	}

	
	public void paintComponent(Graphics g){
		super.paintComponent(g);
		g.setColor(Color.LIGHT_GRAY);
		g.drawString("弃牌堆("+discardZone.getCardSize()+")", 10, 15);
		int currentW = MainFrame.CARD_W ;
		int currentH = MainFrame.CARD_H ;
		int currentX = (this.getWidth()-currentW)/2 -2*4;
		int currentY = (this.getHeight()-currentH)/2 + 4;
		int startIndex = discardZone.getCardSize()-8-1;
		if(startIndex<0){
			startIndex=0;
		}
		for(int count=0; startIndex<discardZone.getCardSize() && count<8; count++ ,startIndex++){
			// TODO 正面
			BufferedImage image = null;
			try {
				image = discardZone.getCards().get(startIndex).cardEntity.getBufferedImage() ;
			} catch (IOException e) {
				e.printStackTrace();
			}
			g.drawImage(image,currentX, currentY, currentW, currentH, null);
			currentX +=2;
			currentY --;
		}
	}
	
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
	}
	
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
	}
	
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

}
